package com.diver.flinkdemo.service;

import com.alibaba.fastjson.JSONObject;
import com.diver.flinkdemo.controller.DalDataController;
import com.diver.flinkdemo.entity.DalData;
import com.diver.flinkdemo.entity.PushData;
import com.diver.flinkdemo.entity.xxt.TerminalUnit;
import com.diver.flinkdemo.service.ITerminalUnitService;
import com.diver.flinkdemo.service.impl.TerminalUnitServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.formula.functions.T;

import java.lang.reflect.InvocationTargetException;
import java.text.ParseException;

/**
 * @author LuJW
 * @date 2023/4/28 11:30
 */
@Slf4j
public class PushDataService {

    private ITerminalUnitService terminalUnitService = new TerminalUnitServiceImpl();

    public String handDalData(String s) throws InvocationTargetException, IllegalAccessException, ParseException {
        if (StringUtils.isNotBlank(s)) {
            DalData dalData = DalData.convert(s);
            DalDataController dalDataController = new DalDataController();
            PushData pushData = dalDataController.dalSendApp(dalData);
            log.info("handDalData1");
            //msgId: xsz_1682666032749
            if(pushData!=null && pushData.getSendType()!=null) {
                log.info("handDalData2");
                String cardNum = dalData.getImei();
                //学生证类型为11
                log.info("handDalData3");
                TerminalUnit terminalUnit = terminalUnitService.getOneByCardNum(cardNum, 11);
                log.info("handDalData7");
                pushData.setTerminalUnit(terminalUnit);
                return JSONObject.toJSONString(pushData);
            }
        }
        return "";
    }
}
